using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class ShowVisiGroupsContactsPage : BasePage
	{
		private const string TAG = "ShowVisiGroupsContactsPage";
		private const int cNPageArgCnt = 1;
		private List<SnsTagInfo> mListSnsGroup;
		private ObservableCollection<Group<Contact>> mListGroupContacts = new ObservableCollection<Group<Contact>>();
		private EventWatcher mWatchxxx;
		private object mObjectWatcher = new object();
		internal Grid LayoutRoot;
		internal LongListSelector longListCons;
		private bool _contentLoaded;
		public ShowVisiGroupsContactsPage()
		{
			this.InitializeComponent();
		}
		protected override void OnPageLoaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("ShowVisiGroupsContactsPage", "Page_Loaded");
		}
		protected override void OnPageUnLoaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("ShowVisiGroupsContactsPage", "Page_Unloaded");
		}
		protected override void OnPageIn(object[] object_0)
		{
			Log.smethod_5("ShowVisiGroupsContactsPage", "OnPageIn");
			if (object_0 != null)
			{
				if (1 == object_0.Length)
				{
					if (object_0[0] is List<ulong>)
					{
						List<ulong> list = object_0[0] as List<ulong>;
						if (list == null)
						{
							goto IL_AA;
						}
						this.mListSnsGroup = new List<SnsTagInfo>();
						using (List<ulong>.Enumerator enumerator = list.GetEnumerator())
						{
							while (enumerator.MoveNext())
							{
								ulong current = enumerator.get_Current();
								SnsTagInfo snsTagInfo = StorageMgr.snsTag.method_1(current.ToString("X16"));
								if (snsTagInfo != null)
								{
									this.mListSnsGroup.Add(snsTagInfo);
								}
							}
							goto IL_AA;
						}
					}
					if (object_0[0] is List<SnsTagInfo>)
					{
						this.mListSnsGroup = (object_0[0] as List<SnsTagInfo>);
					}
					IL_AA:
					this.initUI();
					return;
				}
			}
			base.GoBack();
		}
		protected override void OnPageOut()
		{
			Log.smethod_5("ShowVisiGroupsContactsPage", "OnPageOut");
		}
		protected override void OnPageBack()
		{
			Log.smethod_5("ShowVisiGroupsContactsPage", "OnPageBack");
		}
		private void registerEvent()
		{
			if (this.mWatchxxx == null)
			{
				this.mWatchxxx = new EventWatcher(this.mObjectWatcher, null, new EventHandlerDelegate(this.Onxxx));
				EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatchxxx != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
				this.mWatchxxx = null;
			}
		}
		private void Onxxx(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
		}
		private void longListCons_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (this.longListCons.SelectedItem == null)
			{
				return;
			}
			Contact contact = this.longListCons.SelectedItem as Contact;
			if (contact != null)
			{
				object[] passData = new object[]
				{
					contact
				};
				SnsUserMainPage.GoToThisPage(passData);
			}
			this.longListCons.SelectedItem = null;
		}
		private void initUI()
		{
			if (this.mListSnsGroup != null && this.mListSnsGroup.get_Count() != 0)
			{
				using (List<SnsTagInfo>.Enumerator enumerator = this.mListSnsGroup.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						SnsTagInfo current = enumerator.get_Current();
						if (current != null && !string.IsNullOrEmpty(current.strTagName))
						{
							List<Contact> contactsFromGroup = SnsGroupMgr.GetContactsFromGroup(current);
							Group<Contact> group = new Group<Contact>(current.strTagName, contactsFromGroup);
							this.mListGroupContacts.Add(group);
						}
					}
				}
				this.longListCons.ItemsSource = this.mListGroupContacts;
				return;
			}
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
		}
		public static void GotoThisPage(object object_0)
		{
			object[] object_ = new object[]
			{
				object_0
			};
			ToolFunction.GotoPageForUserControl("/Source/Plugin/Sns/Common/UI/SnsGroup/ShowVisiGroupsContactsPage.xaml", object_, false);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Sns/Common/UI/SnsGroup/ShowVisiGroupsContactsPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.longListCons = (LongListSelector)base.FindName("longListCons");
		}
	}
}
